
    /**  
    * @Title: InterceptorConfiguration.java
    * @Package com.efast.cafe.framework.interceptor.config
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2018年8月21日
    * @version V1.0  
    */
    
package com.efast.cafe.framework.interceptor.config;

import java.util.regex.Pattern;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.efast.cafe.framework.constant.SecurityConstant;
import com.efast.cafe.framework.feign.constant.FeignConstant;
import com.efast.cafe.framework.interceptor.FileUploadInterceptor;
import com.efast.cafe.framework.interceptor.ReqHeaderAndResHeaderInterceptor;

/**
    * @ClassName: InterceptorConfiguration
    * @Description: 注册springMVC拦截器
    * @author Administrator
    * @date 2018年8月21日
    *
    */
@Component
public class InterceptorConfiguration extends WebMvcConfigurerAdapter{

	@Autowired
	private ReqHeaderAndResHeaderInterceptor reqHeaderAndResHeaderInterceptor;
	
	@Autowired
	private FileUploadInterceptor fileUploadInterceptor;
	
	
	    /* (非 Javadoc)
	    * 
	    * 
	    * @param registry
	    * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry)
	    */
	    
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 注册拦截器 请求头和响应头处理（缓存数据）
        InterceptorRegistration ir = registry.addInterceptor(reqHeaderAndResHeaderInterceptor);
        // 配置拦截的路径
        ir.addPathPatterns("/**");
        // 配置不拦截的路径
        //ir.excludePathPatterns("/**.html");
        ir.excludePathPatterns("/openHTTP/*");
        ir.excludePathPatterns("/openWS/*");
        ir.excludePathPatterns(SecurityConstant.LOGIN_PATH);
        ir.excludePathPatterns(SecurityConstant.LOGOUT_PATH);
        ir.excludePathPatterns(FeignConstant.Scope.FEIGN_SCOPE_PV+"/**");
        ir.excludePathPatterns(FeignConstant.Scope.FEIGN_SCOPE_PV_AUTH+"/**");
        
        //文件上传拦截器
        InterceptorRegistration ir2 = registry.addInterceptor(fileUploadInterceptor);
        ir2.addPathPatterns("/**");
        ir2.excludePathPatterns("/openHTTP/*");
        ir2.excludePathPatterns("/openWS/*");
        ir2.excludePathPatterns(SecurityConstant.LOGIN_PATH);
        ir2.excludePathPatterns(SecurityConstant.LOGOUT_PATH);
        ir2.excludePathPatterns(FeignConstant.Scope.FEIGN_SCOPE_PV+"/**");
        ir2.excludePathPatterns(FeignConstant.Scope.FEIGN_SCOPE_PV_AUTH+"/**");
	}
}
